import { Injectable } from '@angular/core';
import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, CanDeactivate } from '@angular/router';
import { Observable } from 'rxjs/Observable';
import { CanDeactivateInterface } from "./can-deactivate.Interface";

@Injectable()
export class CanDeactivateGuard implements CanDeactivate<CanDeactivateInterface> {
  canDeactivate(
    component: CanDeactivateInterface,
    currentRoute: ActivatedRouteSnapshot,
    currentState: RouterStateSnapshot,
    nextState?: RouterStateSnapshot): boolean | Observable<boolean> | Promise<boolean> {
    if (component && component.canDeactivate != null) {
      return component.canDeactivate();
    }
    else {
      return true;
    }
  }
}




// WEBPACK FOOTER //
// ./src/app/service/guard/can-deactivate.guard.ts